package cn.seaboot.admin.net.manager;

import cn.seaboot.admin.net.prop.HttpClientProperties;
import cn.seaboot.commons.http.HttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * Configuration for HttpClientConstant,
 *
 * @author Mr.css
 * @version 2020-05-28 14:56
 */
@Configuration
public class HttpClientStarter {

    @Resource
    private HttpClientProperties httpClientProperties;

    /**
     * create a HttpClient instance
     *
     * @return HttpClient
     */
    @Bean
    public HttpClient createHttpClient() {
        HttpClient client = new HttpClient();
        if (!httpClientProperties.isEnable()) {
            // 如果是禁用的，设置一个默认的，这个对象用于请求转发
            client.withDefaultSetting();
        } else {
            // 使用配置数据构造一个Client
            client.withProperties(httpClientProperties);
        }
        return client;
    }
}
